Transactions Sample
The new System.Transactions namespace allows you to create applications that can participate in transactions
like those managed by the Microsoft Distributed Transaction Coordinator (DTC) or use the new LightweightTransactionManager
for simple transactions. The TransactionScope class allows small portions of code to participate in a transaction.
You can also use the IEnlistmentNotification, ISinglePhaseNotification interfaces to create your own transactional
version of common operations such as file copies, deletes or registry changes.
In this example we show how to combine a database call and file copy into a transaction using the TransactionScope class.
If the transaction fails, both the database operations and the file copy are rolled back.
This sample requires the following to be installed:
- Visual Studio 2005.
- SQL Server Express 2005.
- AdventureWorks Sample Database
Depending upon your installation, you may also need to modify the connection string
which is defined in the file Form1.cs, line 107. The sample
copies the "ReadMe.htm" file from this project as part of the sample, so if you
copy this project to another folder, be sure to include this file. You may also need to ensure
that you have the correct credentials to access the AdventureWorks sample database.